home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / basic / winborder.lha / border.bb2
Encoding:
Text File  |  1999-05-27  |  4.0 KB  |  109 lines

  1. ; Description:      Shows how to get the various border sizes of a window *before* it
  2. ;                   is opened
  3. ;
  4. ; Type:             Intuition
  5. ;
  6. ; Last updated:     27th May 1999
  7. ;
  8. ; Author:           David McMinn, from example by Massimo Tantignone
  9. ;
  10. ; Requires:         amigalibs.res
  11. ;
  12.  
  13. WBStartup
  14. WbToScreen 0
  15. *scr.Screen = Peek.l(Addr Screen(0))
  16.  
  17.  
  18. ; You pass the address of the variables you want to store the result in, they must be
  19. ; longword variables (.l type). If you do not want one of the sizes returned, then you
  20. ; can pass 0 as the parameter, and it will be ignored.
  21. ; NB: You MUST have a currently used screen before calling this statement
  22. ;
  23. Statement SizeGadBorders{*right.l,*bottom.l}
  24.     DEFTYPE.Screen      *scr    ; Pointer to a screen
  25.     DEFTYPE.DrawInfo    *dri    ; The drawing information of that screen
  26.     DEFTYPE.Image       *img    ; An image which represents the size gadget
  27.     DEFTYPE.l           sis     ; Size of image for either medium res or lo res screens
  28.     DEFTYPE.l           rightborderthickness  ; The thickness the borders would be if
  29.     DEFTYPE.l           bottomborderthickness ; a size gadget is on the window
  30.     Dim                 tags.TagItem(4) ; Tags for getting the size gadget image
  31.  
  32.     ; Initial fallback values
  33.     rightborderthickness = 18
  34.     bottomborderthickness = 10
  35.  
  36.     ; Get address of currently used screen and then the drawing information for it
  37.     *scr = Peek.l(Addr Screen(Used Screen))
  38.     *dri = GetScreenDrawInfo_(*scr)
  39.  
  40.     If *dri
  41.         ; If we got a pointer to the drawing information, check what size of image
  42.         ; the size gadget will be.
  43.         If (*scr\Flags & #SCREENHIRES) Then sis=#SYSISIZE_MEDRES Else sis=#SYSISIZE_LOWRES
  44.  
  45.         ; Create tags for getting size gadget image and then get the image (using BOOPSI)
  46.         tags(0)\ti_Tag = #SYSIA_DrawInfo,*dri
  47.         tags(1)\ti_Tag = #SYSIA_Which,#SIZEIMAGE
  48.         tags(2)\ti_Tag = #SYSIA_Size,sis
  49.         tags(3)\ti_Tag = #TAG_DONE
  50.         *img = NewObjectA_(0,"sysiclass",&tags(0))
  51.         If *img
  52.             ; If we got the image, then we get the width and height of the image, which
  53.             ; turn out to be the width and height of the right and bottom borders.
  54.             ; We don't need the image after this, so get rid of it as well
  55.             rightborderthickness = *img\Width
  56.             bottomborderthickness = *img\Height
  57.             DisposeObject_ *img
  58.         End If
  59.  
  60.         ; Free the drawing information for the screen
  61.         FreeScreenDrawInfo_ *scr,*dri
  62.     End If
  63.  
  64.     ; Store the values, only if the parameter passed was not 0. Poke is used here
  65.     ; (even though I think it looks untidy) because of the way Blitz handles
  66.     ; pointers (i.e. poorly) to the basic types, in this case a .l
  67.     If *right Then Poke.l *right,rightborderthickness
  68.     If *bottom Then Poke.l *bottom,bottomborderthickness
  69. End Statement
  70.  
  71.  
  72. ; Print values of window borders to default output *before* opening a window
  73. NPrint "Values calculated before opening window"
  74. NPrint "Left border = ",*scr\WBorLeft
  75. NPrint "Top border = ",*scr\WBorTop
  76. NPrint "Right border = ",*scr\WBorRight
  77. NPrint "Bottom border =",*scr\WBorBottom
  78.  
  79. NPrint ""
  80.  
  81. NPrint "Title bar height = ",*scr\WBorTop + *scr\Font\ta_YSize + 1
  82. DEFTYPE.l r,b
  83. SizeGadBorders{&r,&b}
  84. NPrint "Right border width (with size gadget) = ",r
  85. NPrint "Bottom border height (with size gadget) = ",b
  86.  
  87. NPrint ""
  88.  
  89. ; You can check the different styles of border by using ONLY ONE of these lines
  90. ;Window 0,0,0,200,200,$100f,"Test",-1,-1                                     ; Size gadget, right border
  91. ;Window 0,0,0,200,200,$100f|#WFLG_SIZEBBOTTOM,"Test",-1,-1                   ; Size gadget, bottom border
  92. Window 0,0,0,200,200,$100f|#WFLG_SIZEBBOTTOM|#WFLG_SIZEBRIGHT,"Test",-1,-1  ; Size gadget, right border
  93.  
  94.  
  95. *win.Window = Peek.l(Addr Window(0))
  96. DefaultOutput
  97.  
  98. NPrint "Values found after opening window"
  99. NPrint "Left border = ",*win\BorderLeft
  100. NPrint "Top border = ",*win\BorderTop
  101. NPrint "Right border = ",*win\BorderRight
  102. NPrint "Bottom border = ",*win\BorderBottom
  103.  
  104. While ev.l<>#IDCMP_CLOSEWINDOW
  105.     ev=WaitEvent
  106. Wend
  107. End
  108.  
  109.